#include<stdio.h>
#define MAXN 100
int main()
{
    freopen("in.txt","r",stdin);
    printf("请输入n和m\n");
    int n,m;
    scanf("%d %d",&n,&m);
    if( n <= 0 || m <= 0)
    {
        printf("输入错误\n");
        return -1;
    }
    int Stack[MAXN][3];
    int top = 0;
    Stack[top][0] = 0;
    Stack[top][1] = n;
    Stack[top][2] = m;
    top++;
    do
    {
        //printf("top = %d\n",top);
        if(Stack[top-1][2] == 0 && Stack[top-1][0] ==0 )
        {
            Stack[top-1][0] = Stack[top-1][1] + 1;
        }
        else
        if(Stack[top-1][1] == 0 && Stack[top-1][0] ==0 )
        {
            Stack[top][0] = 0;
            Stack[top][1] = 1;
            Stack[top][2] = Stack[top-1][2] - 1;
            top++;
        }
        else
        if(Stack[top-1][0] == 0 )
        {
            Stack[top][0] = 0;
            Stack[top][1] = Stack[top-1][1] - 1;
            Stack[top][2] = Stack[top-1][2];
            top++;
        }
        if(Stack[top-1][0] != 0)
        {
            if(Stack[top-2][1] == 0)
            {
                Stack[top-2][0] = Stack[top-1][0];
                top--;
            }
            else
            {
                Stack[top-2][1] = Stack[top-1][0];
                Stack[top-2][2] = Stack[top-2][2] - 1;
                top--;
            }
        }
    } while (Stack[0][0] == 0);
    printf("%d\n",Stack[0][0]);
}